feat(ollama): detect and report GPU vs CPU execution (issue #11)#155
Merged
Conversation
Add a RuntimeStatus domain model with a device field (gpu/cpu/unknown) and a status() method on RuntimePort. OllamaRuntime detects the device from ollama ps VRAM usage (size_vram > 0 => GPU). The load CLI now prints the device after a successful load. Co-Authored-By: Claude <noreply@anthropic.com>
|
🎉 Congratulations @himanshu231204! Your pull request has been successfully merged into main. 🚀 Thank you for contributing to OpenAgentHQ and helping improve the project. We truly appreciate your contribution and hope to see you back with more amazing PRs! Happy Open Sourcing! ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #11. When loading a model via Ollama there was no signal whether execution runs on GPU or CPU. This adds a runtime status object that reports the execution device, and surfaces it from the
loadCLI.Changes
domain/model.py): addedDeviceenum (gpu/cpu/unknown) and a pureRuntimeStatuspydantic model (backend,available,device,loaded_models,details). No I/O, per the architecture's purity rule.ports/runtime.py): addedstatus() -> RuntimeStatustoRuntimePort.adapters/runtimes/base.py):status()reports availability + device;_detect_device()hook defaults toUNKNOWNso other runtimes get the contract for free.adapters/runtimes/ollama.py):_detect_device()callsclient.ps()and inspectssize_vramper loaded model —> 0=> GPU,0/None => CPU, no models loaded =>UNKNOWN. Best-effort: a failingps()never breaks the status probe.core/manager.py,cli/commands/load.py):ModelManager.runtime_status()delegates to the runtime;loadnow printsDevice: <gpu|cpu|unknown>after a successful load.Acceptance criteria (from #11)
device/executorfield to the runtime status object —RuntimeStatus.deviceollama ps/ API metadata —OllamaRuntime._detect_device()loadprints the device —cli/commands/load.pyTests
tests/unit/test_ollama_runtime.py): GPU (vram>0), CPU (vram=0), UNKNOWN (no models), UNKNOWN (ps raises), unavailable (daemon down) — all with a fake client.tests/unit/test_port_contract.py):status()returns a validRuntimeStatuswith a known device value;FakeRuntimeinconftest.pygainedstatus().tests/integration/test_ollama.py):test_ollama_status_device_detectionloads a local model and cross-checks the detected device againstollama ps(auto-skips without a daemon; cloud/subscription models are filtered out).Verification
Ran against a live Ollama daemon (
ollama serve):test_ollama_status_device_detection— passed; correctly reporteddevice=cpu(machine has no usable GPU;ollama psshowed100% CPU,size_vram: 0).ruff checkclean,mypy --strictclean,ruff formatclean.Notes
status()method; existing behavior is unchanged.devicefield is best-effort: it reflects currently-loaded models. If nothing is resident, it reportsunknownrather than guessing.🤖 Generated with Claude